package cate.game.admin.menu.farm;

import cate.common.table.d.GDFunc;
import cate.common.table.farm.spicefb.row.SpiceFbLevelRow;
import cate.game.GameBody;
import cate.game.admin.menu.MenuSetup;
import cate.game.event.tower.TowerPassedEvent;
import cate.game.role.farm.PlayTimes;
import cate.game.role.farm.adventure.msg.AdventurePlayTimesResp;
import cate.game.role.farm.spicefb.SpiceFb;
import cate.game.role.farm.spicefb.po.SpiceFbChapter;
import cate.game.role.farm.spicefb.po.SpiceFbLevel;
import cate.game.role.farm.udgpalace.UdgPalaceItem;
import cate.game.role.farm.udgpalace.UdgPalaceLevel;
import easy.java.practice.errorcode.EcResult;

import java.util.ArrayList;

public class FarmMenu extends MenuSetup {

    public FarmMenu(GameBody gameBody) {
        super("副本相关");

        reg(
                gameBody,
                "改变主线关卡通关数",
                1,
                "【关卡数】:",
                (role, params) -> {
                    if (params.isEmpty()) {
                        gameBody.notice.message(role, "参数不能少于1个!");
                        return;
                    }
                    int num = Integer.parseInt(params.get(0));
                    role.getFarm().adventure.changeCombatIdPassed(num);
                    role.getFarm().adventure.noticeUpdate();
                    gameBody.notice.message(role, "已经改变了你的主线关卡!");
                });

        reg(
                gameBody,
                "食灵神殿次数重置",
                0,
                "",
                (role, params) -> {
                    EcResult<Void> r = role.getFarm().tower.gmClearTowerData();
                    if (!r.ok()) {
                        gameBody.notice.message(role, r.message);
                    } else {
                        gameBody.notice.message(role, "清除辣!");
                    }
                });
        reg(
                gameBody,
                "食灵神殿通关数",
                1,
                "参数1：关卡数",
                (role, params) -> {
                    int level = Integer.parseInt(params.get(0));
                    role.getFarm().tower.passedFloor = level;
                    gameBody.notice.message(role, "设置成功!");
                    role.getFarm().tower.noticeUpdate();
                    publishEvent(gameBody, new TowerPassedEvent(role, level));
                });

        reg(
                gameBody,
                "快速补给次数重置",
                0,
                "",
                (role, params) -> {
                    PlayTimes playTimes = role.getFarm().adventure.playTimes;
                    playTimes.reset();
                    role.sendNow(new AdventurePlayTimesResp(playTimes));
                    gameBody.notice.message(role, "重置成功!");
                });
        reg(
                gameBody,
                "获得挂机奖励",
                1,
                "【挂机分钟数】",
                (role, params) -> {
                    int minutes = toInt(params, 0, 0);
                    if (minutes > 0) {
                        role.getFarm().adventure.calAndSendReward(minutes, GDFunc.QUICK_FIGHT, false);
                    }
                }
        );

        reg(
                gameBody,
                "重新构建迷失神庙地图",
                0,
                "",
                (role, params) -> {
                    role.getFarm().island.gmRebuildMap();
                    gameBody.notice.message(role, "成功!");
                }
        );

        reg(
                gameBody,
                "清空迷失神庙历史系数",
                0,
                "",
                (role, params) -> {
                    role.getFarm().island.failScore = 0;
                    role.getFarm().island.successScore = 0;
                    gameBody.notice.message(role, "成功!");
                }
        );

        reg(
                gameBody,
                "查询迷失神庙历史系数",
                0,
                "",
                (role, params) -> gameBody.notice.message(role, "失败系数：" + role.getFarm().island.failScore + "成功系数" + role.getFarm().island.successScore)
        );

        reg(
                gameBody,
                "水晶峡谷满星跳关",
                1,
                "【参数1】ID （水晶峡谷表的id）",
                (role, params) -> {
                    int combatNumPass = toInt(params, 0, 1);
                    SpiceFb fb = new SpiceFb();
                    fb.initialize(role);
                    fb.checkOpen();
                    fb.combatNumPass = combatNumPass;
                    for (int i = 1; i <= combatNumPass; i++) {
                        SpiceFbLevelRow levelRow = role.getGame().table.spiceFb.level.get(i);
                        if (levelRow == null) {
                            gameBody.notice.message(role, "关卡不存在!");
                            return;
                        }
                        SpiceFbChapter chapter = fb.getChapter(levelRow.chapter);
                        SpiceFbLevel level = chapter.getLevel(levelRow.level);
                        level.pass = true;
                        level.challenge = new ArrayList<>(levelRow.challengeIds);
                        chapter.pass = chapter.levelMap.keySet().size();
                        chapter.star = 3 * chapter.pass;
                        fb.chapterOpen = chapter.chapter;
                    }
                    fb.checkUnLock();
                    role.getFarm().spiceFb = fb;
                    role.getFarm().spiceFb.noticeUpdate();
                    gameBody.notice.message(role, "成功!");
                }
        );

        reg(
                gameBody,
                "日常副本关数调整",
                3,
                "【参数1】副本类型【参数2】开启关数【参数3】通关关数",
                (role, params) -> {
                    int type = toInt(params, 0, 1);
                    int combatNumOpen = toInt(params, 1, 1);
                    int combatNumPass = toInt(params, 2, 1);

                    EcResult<Void> r = role.getFarm().dailyFb.gmOpenLevel(type, combatNumOpen, combatNumPass);
                    if (!r.ok()) {
                        gameBody.notice.message(role, r.message);
                    } else {
                        gameBody.notice.message(role, "成功!");
                    }
                });

        reg(
                gameBody,
                "元素圣殿关数调整",
                3,
                "【参数1】圣殿类型【参数2】已经通关数量【参数3】历史最大通关数",
                (role, params) -> {
                    int roomId = toInt(params, 0, 1);
                    int roundPass = toInt(params, 1, 1);
                    int passMax = toInt(params, 2, 1);

                    EcResult<Void> r = role.getFarm().forbidden.gmOpenLevel(roomId, roundPass, passMax);
                    if (!r.ok()) {
                        gameBody.notice.message(role, r.message);
                    } else {
                        gameBody.notice.message(role, "成功!");
                    }
                });

        reg(
                gameBody,
                "无尽试炼跳关",
                1,
                "【参数1】关数（实际开始挑战关数为 设置关数-10）",
                (role, params) -> role.getFarm().endless.gmJump(Integer.parseInt(params.get(0))));

        reg(
                gameBody,
                "跨服BOSS单个信息",
                1,
                "[参数1] BOSS配置ID",
                (role, params) -> {
                    int id = toInt(params, 0, 1);
                    role.getFarm().crossBoss.viewBossDetail(id);
                }
        );

        reg(
                gameBody,
                "跨服BOSS挑战",
                1,
                "[参数1] BOSS配置ID",
                (role, params) -> {
                    int id = toInt(params, 0, 1);
                    role.getFarm().crossBoss.tryFightBoss(id);
                }
        );

        reg(
                gameBody,
                "地宫探险新增探险道具",
                1,
                "[参数1] 数量",
                (role, params) -> {
                    UdgPalaceItem item = role.getFarm().udgPalace.team.items.get(Integer.parseInt(params.get(0)));
                    if (item == null) {
                        gameBody.notice.message(role, "没有这个道具啊");
                        return;
                    }
                    item.value = 99999;
                    role.getFarm().udgPalace.noticeUpdate();
                    gameBody.notice.message(role, "成功拉");
                }
        );

        reg(
                gameBody,
                "地宫探险跳关",
                1,
                "[参数1] 关数",
                (role, params) -> {
                    UdgPalaceLevel level = role.getFarm().udgPalace.level;
                    level.level = Integer.parseInt(params.get(0));
                    level.events.clear();
                    level.bossHpExtends.clear();
                    role.getFarm().udgPalace.noticeUpdate();
                    gameBody.notice.message(role, "成功拉");
                }
        );

        reg(
                gameBody,
                "重置地宫探险",
                0,
                "",
                (role, params) -> {
                    role.getFarm().udgPalace.reset();
                    role.getFarm().udgPalace.noticeUpdate();
                }
        );
    }
}
